<html lang="en">
<head>
    <title>目的地管理</title>
    <#include "../common/header.ftl">
    <#--<link rel="stylesheet" href="/js/plugins/treeview/bootstrap-treeview.min.css" type="text/css" />-->
    <#--<script type="text/javascript" src="/js/plugins/treeview/bootstrap-treeview.min.js"></script>-->
    <link type="text/css" rel="stylesheet" href="/js/plugins/uploadifive/uploadifive.css" />
    <script type="text/javascript" src="/js/plugins/uploadifive/jquery.uploadifive.min.js"></script>
    <style>
        .textarea1{

            width: 100%;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            //查询节日，填充到模态框中
            $.get("/destinationTags/listFestivals",function (data) {
                if(data.success){
                    var list = data.data;
                    for(var i = 0;i<list.length;i++){
                        var option = "<option value=" + list[i].id + ">" + list[i].name + "</option>";
                        $("#festivalId").append(option);
                    }
                }
            })

            //查询所有主题，填充到模态框中
            $.get("/destinationTags/listThemes",{deep:2},function (data) {
                if(data.success){
                    var list = data.data;
                    for(var i = 0; i < list.length; i++){
                        var option = "<option value=" + list[i].id + ">" + list[i].name + "</option>";
                        $("#destThemeId").append(option);
                    }
                }
            })

            //编辑
            $(".inputBtn").click(function () {
                //弹出模态框
                $("#editModal").modal("show");

                //数据复原
                $("#editForm").clearForm(true);

                //目的地回显数据
                var data = $(this).data("json");
                if(data){
                    $("input[name='id']").val(data.id);
                    $("input[name='name']").val(data.name);
                    $("input[name='headImgUrl']").val(data.headImgUrl);
                    $("#imgUrl").attr("src",data.headImgUrl);
                    $("select[name='month']").val(data.month);
                    $("#festivalId").val(data.festivalId);
                    $("#destThemeId").val(data.destThemeId);
                    $("input[name='days']").val(data.days);
                }
            })
            
            $(".submitBtn").click(function () {
                //模态框表单提交
                $("#editForm").ajaxSubmit(function (data) {
                    if(data.success){
                        window.location.reload();
                    }else{
                        $.messager.alert("温馨提示", data.msg)
                    }
                })
            })

            //查询
            $(".clickBtn").click(function () {
                var destParentId = $(this).data("destparentid");
                $("#destParentId").val(destParentId);
                $("#currentPage").val(1);
                $("#searchForm").submit();
            })

            //图片上传
            $('.imgBtn').uploadifive({
                'auto' : true,  //自动提交
                'uploadScript' : '/uploadImg',  //图片上传过来处理路径（接收）
                buttonClass:"btn-link", //按钮的样式
                'fileObjName' : 'pic',  //图片文件上传之后，在springmVC映射方法接收到额参数名
                'buttonText' : '浏览...',//按钮上面的文字
                'fileType' : 'image',//指定上传的图片
                'multi' : false,//是否为多文件上传，此处设置单文件
                'fileSizeLimit'   : 5242880,//文件上传大小
                'removeCompleted' : true, //取消上传完成提示
                'uploadLimit' : 1,  //上传文件的个数
                //'queueSizeLimit'  : 10,   //文件上传等待队列大小
                'overrideEvents': ['onDialogClose', 'onError'],    //onDialogClose 取消自带的错误提示
                'onUploadComplete' : function(file, data) {     //文件上传成功后，做什么动作
                    //data 请求方法处理完之后，传回来的数据，约定：图片的路径（url）
                    $("#imgUrl").attr("src" , "/" + data);
                    $("#headImgUrl").val("/" + data); //IP：端口 /斜杠

                },
                onFallback : function() {       //失败时候做的操作
                    $.messager.alert("温馨提示","该浏览器无法使用!");
                }
            });

        })
    </script>
</head>
<body>
<!--左侧菜单回显变量设置-->
<#assign currentMenu="destinationTags">

<div class="container-fluid " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">目的地标签管理</h1>
                </div>
            </div>
            <#setting number_format="#">
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/destinationTags/list" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <input type="hidden" name="destParentId" id="destParentId" value="${qo.destParentId!}">
                <div class="form-group">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!''}" placeholder="请输入名称">
                </div>
                <button type="button" class="btn btn-primary clickBtn" data-parentid="${qo.parentId!}"><span class="glyphicon glyphicon-search"></span> 查询</button>
                <#--<button type="button" class="btn btn-success inputBtn"><span class="glyphicon glyphicon-plus"></span>添加</button>-->

               <h4>
                    当前位置: <a href="javascript:;" data-destParentId="-1" class="clickBtn">根</a>
                <#list toasts as t>
                         >> <a href="javascript:;" data-destparentid="${t.id}" class="clickBtn">${t.name}</a>
                </#list>
                </h4>

            </form>

            <table class="table table-striped table-hover" >
                <thead>
                    <tr>
                        <th>序号</th>
                        <th>名称</th>
                        <th>封面</th>
                        <th>推荐旅游月份</th>
                        <th>推荐旅游节日</th>
                        <th>主题</th>
                        <th>推荐旅游天数</th>
                        <th>操作</th>
                    </tr>
                </thead>
               <#list pageInfo.list as entity>
                   <tr>
                       <td>${entity_index+1}</td>
                       <td><a href="/destinationTags/list?destParentId=${entity.destination.id}">${entity.destination.name!}</a></td>
                       <td><img src="${entity.headImgUrl!}" width="100px"/></td>
                       <td>${entity.month!}</td>
                       <td>${(entity.festival.name)!}</td>
                       <td>${(entity.destTheme.name)!}</td>
                       <td>${(entity.days)!}</td>

                       <td>
                           <a class="btn btn-info btn-xs inputBtn" href="javascript:;" data-json='${(entity.jsonString)!}'>
                               <span class="glyphicon glyphicon-edit"></span> 编辑
                           </a>
                       </td>
                   </tr>
               </#list>
            </table>
            <#--分页-->
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>

<#--目的地编辑模态框-->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span> </button>
                <h4 class="modal-title">目的地标签</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/destinationTags/update" method="post" id="editForm">
                    <input type="hidden" value="" name="id">

                    <div class="form-group">
                        <label  class="col-sm-3 control-label">目的地：</label>
                        <div class="col-sm-6">
                            <input type="text"  class="form-control" id="name"  name="name" readonly="readonly">
                        </div>
                    </div>

                    <div class="form-group">
                        <label  class="col-sm-3 control-label">目的地封面：</label>
                        <div class="col-sm-6">
                            <input type="hidden"  class="form-control" id="headImgUrl"  name="headImgUrl" value="" >
                            <img src="/images/girls.jpg" width="100px" id="imgUrl">
                            <button type="button" class="imgBtn">浏览</button>
                        </div>
                    </div>

                    <div class="form-group">
                        <label  class="col-sm-3 control-label">推荐旅游月份：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="month" name="month">
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                                <option value="7">7</option>
                                <option value="8">8</option>
                                <option value="9">9</option>
                                <option value="10">10</option>
                                <option value="11">11</option>
                                <option value="12">12</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label  class="col-sm-3 control-label">推荐旅游节日：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="festivalId" name="festival.id">
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label  class="col-sm-3 control-label">主题：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="destThemeId" name="destTheme.id">
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label  class="col-sm-3 control-label">推荐旅游天数：</label>
                        <div class="col-sm-6">
                            <input type="text"  class="form-control" id="days" name="days">
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary submitBtn" >保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>